import React from 'react';
import {postLsCarPassageSetGlobalGuard} from '../../../../api'
import { Modal, Form, TimePicker, message } from 'antd'
import moment from 'moment'

const ImportAntExportSetModule = ({
    importAndExportSetModuleShow,
    setImportAndExportSetModuleShow,
    setFun
}) => {
    const [form] = Form.useForm()
    const { validateFields, resetFields } = form
    const handleOk = () => {
        validateFields().then(values => {
            values.startTime = moment(values.time[0]).format('HH:mm:ss')
            values.endTime = moment(values.time[1]).format('HH:mm:ss')
            delete values.time
            ; (async () => {
                const { code, msg } = await postLsCarPassageSetGlobalGuard(values)
                if (code === '20000') {
                    message.success('设置成功！')
                    resetFields()
                    setFun()
                    setImportAndExportSetModuleShow(false);
                } else {
                    message.error(msg)
                }
            })()
        })

    };

    const handleCancel = () => {
        setImportAndExportSetModuleShow(false);
    };
    return <Modal title="设置车辆进出时间" visible={importAndExportSetModuleShow} onOk={handleOk} onCancel={handleCancel}>
        <Form
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 16 }}
            form={form}
        >
            <Form.Item
                label=""
                name="time"
                rules={[{ required: true, message: '请选择车辆进出时间!' }]}
            >
                <TimePicker.RangePicker />
            </Form.Item>
        </Form>
    </Modal>
}

export default ImportAntExportSetModule